package org.akomantoso.core.data;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.akomantoso.core.data.group.HTMLBlock;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.visitor.AKVisitor;

/**
 * <pre>
 * <xsd:element name="table">
 * 		<xsd:complexType>
 * 			<xsd:sequence>
 * 				<xsd:element ref="caption" minOccurs="0" maxOccurs="1"/>
 * 				<xsd:element ref="tr" minOccurs="1" maxOccurs="unbounded"/>
 * 			</xsd:sequence>
 * 			<xsd:attributeGroup ref="corereq"/>
 * 			<xsd:attribute name="width" type="xsd:integer"/>
 * 			<xsd:attribute name="border" type="xsd:integer"/>
 * 			<xsd:attribute name="cellspacing" type="xsd:integer"/>
 * 			<xsd:attribute name="cellpadding" type="xsd:integer"/>
 * 		</xsd:complexType>
 * </xsd:element>
 * </pre>
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 * @since http://www.akomantoso.org/1.0
 */
public final class Table extends CoreReqImpl implements HTMLBlock {

	public static final String ELEMENT = "table";
	
	private Caption _caption;
	private List<Tr> _trs;
	
	private Integer _width;
	private Integer _border;
	private Integer _cellspacing;
	private Integer _cellpadding;

	public Caption getCaption() {
		return _caption;
	}

	public void setCaption(Caption caption) {
		_caption = caption;
	}
	
	public List<Tr> getTrs() {
		return _trs;
	}

	public void setTrs(List<Tr> trs) {
		_trs = trs;
	}

	public void addTr(Tr tr) {
		if (_trs == null) {
			_trs = new ArrayList<Tr>();
		}
		_trs.add(tr);
	}

	public Integer getWidth() {
		return _width;
	}

	public void setWidth(Integer width) {
		_width = width;
	}

	public Integer getBorder() {
		return _border;
	}

	public void setBorder(Integer border) {
		_border = border;
	}

	public Integer getCellspacing() {
		return _cellspacing;
	}

	public void setCellspacing(Integer cellspacing) {
		_cellspacing = cellspacing;
	}

	public Integer getCellpadding() {
		return _cellpadding;
	}

	public void setCellpadding(Integer cellpadding) {
		_cellpadding = cellpadding;
	}

	/**
	 * @see org.akomantoso.core.io.Externalizable#writeExternal(org.akomantoso.core.io.Output)
	 */
	public <T extends Output> void writeExternal(T out) throws IOException {
		out.writeStart(ELEMENT);
		super.writeExternal(out);
		for (int i = 0, n = _trs.size(); i < n; i++) {
			_trs.get(i).writeExternal(out);
		}
		out.writeEnd();
	}
	

	/**
	 * @see org.akomantoso.core.io.Externalizable#readExternal(org.akomantoso.core.io.Input)
	 */
	public <T extends Input> void readExternal(T in) throws IOException {
		super.readExternal(in);
		// TODO
	}
	
	/**
	 * @see ec.ep.visitor.AKVisitable#accept(ec.ep.visitor.AKVisitor)
	 */
	public void accept(AKVisitor visitor) {
		throw new RuntimeException();
	}
}